package com.xique.park.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xique.common.core.constant.Constants;
import com.xique.park.bean.domain.ParkInfo;
import com.xique.park.bean.dto.ParkInfoStatisticsDto;
import com.xique.park.mapper.ParkInfoMapper;
import com.xique.park.service.service.IParkInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ParkInfoServiceImpl
 *
 * @author wld
 * @date 2022/3/9 14:14
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class ParkInfoServiceImpl extends ServiceImpl<ParkInfoMapper, ParkInfo> implements IParkInfoService {

    private final ParkInfoMapper parkInfoMapper;

    @Override
    public ParkInfo selectParkInfoById(Long id) {
        return parkInfoMapper.selectParkInfoById(id);
    }

    @Override
    public ParkInfoStatisticsDto selectOnLineStatus(Integer province, Integer city, Integer district, Long deptId, Long parkInfoId) {
        return parkInfoMapper.selectOnLineStatus(province, city, district, deptId, parkInfoId);
    }

    @Override
    public Integer selectParkNum(Integer province, Integer city, Integer district,
                                 Long deptId, Long parkInfoId) {
        return parkInfoMapper.selectParkNum(province, city, district, deptId, parkInfoId);
    }

    @Override
    public List<ParkInfoStatisticsDto> selectParkListByArea(Integer country, Integer province, Integer city, Integer district,
                                                            Long deptId, Long parkInfoId) {
        return parkInfoMapper.selectParkListByArea(country, province, city, district, deptId, parkInfoId);
    }

    @Override
    public List<ParkInfo> getDeptId(Long deptId) {
        LambdaQueryWrapper<ParkInfo> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(ParkInfo::getDeptId, deptId);
        // 启用状态
        queryWrapper.eq(ParkInfo::getStatus, Constants.NORMAL);
        // 启用状态
        queryWrapper.eq(ParkInfo::getRecordStatus, Constants.NORMAL);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public List<ParkInfo> getDeptIds(List<Long> deptIdList) {
        LambdaQueryWrapper<ParkInfo> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.in(ParkInfo::getDeptId, deptIdList);
        // 启用状态
        queryWrapper.eq(ParkInfo::getStatus, Constants.NORMAL);
        // 启用状态
        queryWrapper.eq(ParkInfo::getRecordStatus, Constants.NORMAL);
        return baseMapper.selectList(queryWrapper);
    }

    @Override
    public ParkInfo selectParkInfoWithAreaById(Long id) {
        return parkInfoMapper.selectParkInfoWithAreaById(id);
    }

    @Override
    public List<ParkInfo> selectParkInfoByDeptId(Long deptId) {
        LambdaQueryWrapper<ParkInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ParkInfo::getDeptId, deptId);
        queryWrapper.eq(ParkInfo::getStatus, Constants.NORMAL);
        queryWrapper.eq(ParkInfo::getRecordStatus, Constants.NORMAL);
        return list(queryWrapper);
    }

    @Override
    public List<ParkInfo> selectAll() {
        LambdaQueryWrapper<ParkInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ParkInfo::getStatus, Constants.NORMAL);
        queryWrapper.eq(ParkInfo::getRecordStatus, Constants.NORMAL);
        return list(queryWrapper);
    }

    @Override
    public List<ParkInfo> selectNearByParkInfo(double minlng, double maxlng, double minlat, double maxlat, String keyWord) {
        return  parkInfoMapper.selectNearByParkInfo(minlng,maxlng,minlat,maxlat,keyWord);
    }

}
